home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / sound / rukc1d.zip / RUCK_SRC.ZIP / X03.C < prev    next >
C/C++ Source or Header  |  1994-02-27  |  7KB  |  254 lines

  1.  
  2. #include <dos.h>
  3. #include <conio.h>
  4. #include <stdio.h>
  5. #include <stdlib.h>
  6. #include <stdarg.h>
  7.  
  8. #include "ruckdac.h"
  9.  
  10. /*
  11. X03.c 27-Feb-94 chh
  12. Record from device to DOS memory or XMS
  13. removed C7-specific _ all over the place
  14. */
  15.  
  16. /*
  17. The following structures are in ruckdac.h
  18. */
  19.  
  20. #pragma pack(1)
  21.  
  22. extern struct DacDataArea pascal DACDATA;
  23.  
  24. struct SysInfoPack SIP;
  25. struct InitPack IP;
  26. struct XitPack XP;
  27. struct LoadPack LP;
  28. struct SetPack SP;
  29. struct SetProPack SPP;
  30. struct PlaybackPack PBP;
  31. struct RecordPack RP;
  32. struct DeallocPack DP;
  33.  
  34. #pragma pack()
  35.  
  36. int rez, rez2;      /* result status codes */
  37. char nums[9] = {7}; /* number buffer for _cgets()*/
  38. char filename[81];  /* pathname to load */
  39.  
  40.  
  41. int pick_device(int *devID, int *XMSflag)
  42. {
  43.  
  44.     int td=0;
  45.  
  46.     SIP.Func = SysInfoDac;
  47.     rez = RUCKDAC(&SIP);
  48.     if (rez == 0) {
  49.         printf("CPU is a %u/%u\n",SIP.CPU,SIP.MHz);
  50.  
  51.         printf("\n0. End program");
  52.         if (SIP.SD[4].device)
  53.             printf("\n5. Sound Blaster, port %xh",SIP.SD[4].Port);
  54.         if (SIP.SD[5].device)
  55.             printf("\n6. Sound Blaster Pro, port %xh",SIP.SD[5].Port);
  56.         if (SIP.SD[4].device)
  57.             printf("\n\n7. Sound Blaster as 5 but use XMS (if applicable)");
  58.         if (SIP.SD[5].device)
  59.             printf("\n8. Sound Blaster Pro as 6 but use XMS (if applicable)\n");
  60.  
  61.         printf("\nSelection: ");
  62.     td = atoi(cgets(nums));
  63.         td--;   /* since devices are numbered 0 to 5 */
  64.  
  65.         if (td > 6) {
  66.             *XMSflag = -1;      /* XMS memory selected with SB */
  67.                                 /* use -1 so as to auto-alloc below */
  68.             td-=2;              /* map to appropriate device */
  69.         }
  70.  
  71.         if ((td >=4) && (td <=5)) { /* validate device selected is available */
  72.             if (SIP.SD[td].device == 0)
  73.                 td = -1;
  74.         }
  75.         else
  76.             td = -1;
  77.     }
  78.  
  79.     *devID = td;
  80.     return(rez);
  81. }
  82.  
  83.  
  84. int init_device(int devID)
  85. {
  86.     /*
  87.     Initialize RUCKDAC and device and register ExitDac with _atexit
  88.     */
  89.  
  90.     IP.Func = InitDac;
  91.     IP.DeviceID = devID;
  92.     IP.IOport = SIP.SD[devID].Port;
  93.     IP.IRQline = SIP.SD[devID].IRQ;
  94.     IP.DMAch = SIP.SD[devID].DMA;
  95.  
  96.     rez = RUCKDAC(&IP);                 /* Initialize */
  97.     if (rez == 0) {
  98.         XP.Func = AtExitDac;
  99.         rez2 = RUCKDAC(&XP);
  100.         if (rez2 != 0) {
  101.             printf("AtExitDac failed, press Enter to continue");
  102.             getchar();
  103.         }
  104.  
  105.  
  106.         /*
  107.         Increase SB Pro main and vol volumes to max
  108.         */
  109.  
  110.         if (devID == 5) {
  111.             SPP.Func = SetVolMainSBP;
  112.             SPP.Volume = 0x0F0F;
  113.             rez2 = RUCKDAC(&SPP);
  114.             SPP.Func = SetVolVocSBP;
  115.             SPP.VolVoc = 0x0F0F;
  116.             rez2 = RUCKDAC(&SPP);
  117.         }
  118.     }
  119.     return(rez);
  120. }
  121.  
  122.  
  123. int main()
  124. {
  125.  
  126.     int devID=-1, XMSflag = 0;
  127.     unsigned int RecSecs=5, RecRate=12000;
  128.  
  129.  
  130.     printf("X03.C - RUCKUS-DAC record to memory example. [930228]\n");
  131.  
  132.     rez = pick_device(&devID, &XMSflag);
  133.     if (devID >= 0) {
  134.         printf("Initializing devID %u\n",devID);
  135.         rez = init_device(devID);
  136.  
  137.         /*
  138.         The following record example source is coded inline here
  139.         to simply readability -- but it's so easy to add things that I just
  140.         kept adding stuff, so take it slow if you don't follow at first
  141.         */
  142.  
  143.         if (rez == 0) {
  144.  
  145.             /*
  146.             Select input source
  147.             */
  148.  
  149.             SPP.Func = SetSourceSBP;
  150.             SPP.SourceIn = 0;       /* 0=mic,1=CD,2=line */
  151.             rez = RUCKDAC(&SPP);    /* should always check rez status */
  152.                                     /* (not like I'm doing here!) */
  153.  
  154.             printf("   Device ID: %u\n",devID);
  155.             printf(" Record from: mic\n");
  156.             printf(" Record time: %u secs\n",RecSecs);
  157.             printf(" Record rate: %u Hz\n",RecRate);
  158.  
  159.             /*
  160.             Following is memory available for record. We don't use
  161.             it (but should) and just record for 5 secs at 12kHz (~60K)
  162.             */
  163.  
  164.             if (XMSflag == 0) {
  165.                 printf(" Memory type: DOS\n");
  166.                 printf("K bytes free: %u\n",DACDATA.MemDOS);
  167.             }
  168.             else {
  169.                 printf(" Memory type: XMS\n");
  170.                 printf("K bytes free: %u\n",DACDATA.MemXMM);
  171.             }
  172.  
  173.             /*
  174.             Prepare for record (5 secs at 12000Hz sample rate)
  175.             */
  176.  
  177.             RP.Func = RecordDac;
  178.             RP.SampleRate = RecRate;
  179.             RP.XMMhandle = XMSflag;   /* if -1 auto-alloc an XMS handle */
  180.             RP.RecordPtr = NULL;      /* if DOS mem then auto-alloc it */
  181.                                       /* also used to return ptr after Rec*/
  182.  
  183.             /* RecordBytes limit is 16MB (VOC block limit) */
  184.  
  185.             RP.RecordBytes = ((long)RecRate * (long)RecSecs);
  186.             RP.StereoFlag = 0;  /* recording from mic is mono */
  187.  
  188.             printf("\nPress Enter to begin recording...");
  189.             gets(filename);
  190.  
  191.             rez = RUCKDAC(&RP);
  192.  
  193.             /*
  194.             Since record is done as a background DMA task, we can do just
  195.             about anything we want while the recording is taking place.
  196.             Here, I'll just wait until the recording is over
  197.             */
  198.  
  199.             do                          /* I don't think DACDATA needs a  */
  200.                 ;
  201.             while (DACDATA.End == 0);   /* VOLATILE... CONST... both... ? */
  202.  
  203.             /*
  204.             Recording over. Play it back.
  205.             */
  206.  
  207.             printf("Recorded %lu bytes, press Enter to playback recording...",DACDATA.RecordLen);
  208.             gets(filename);
  209.  
  210.             PBP.Func = PlayDac;
  211.             PBP.Mode = 2;
  212.             if (XMSflag == 0) {
  213.                 PBP.XMMhandle = 0;
  214.                 PBP.LoadPtr = RP.RecordPtr;
  215.             }
  216.             else {
  217.                 PBP.XMMhandle = RP.XMMhandle;
  218.                 PBP.LoadPtr = NULL;
  219.             }
  220.             rez = RUCKDAC(&PBP);
  221.  
  222.             do                          /* hang around until it's done */
  223.                 ;
  224.             while (DACDATA.End == 0);
  225.  
  226.             XP.Func = EndDac;           /* end play */
  227.             rez = RUCKDAC(&XP);
  228.  
  229.             /*
  230.             Release memory used by RecordDac (ExitDac would do that, too)
  231.             */
  232.  
  233.             DP.Func = DeallocDac;
  234.             if (XMSflag == 0) {
  235.         DP.HandSeg = FP_SEG(RP.RecordPtr);
  236.                 DP.TypeFlag = 0;
  237.             }
  238.             else {
  239.                 DP.HandSeg = RP.XMMhandle;
  240.                 DP.TypeFlag = 1;
  241.             }
  242.         }
  243.         else
  244.             printf("Initialization failed, %u\n", rez);
  245.     }
  246.     else
  247.         puts("Device pick failed");
  248.  
  249. XP.Func = ExitDac;
  250. rez = RUCKDAC(&XP);
  251. return(rez);
  252.  
  253. }
  254.